<template>
  <!-- 车辆信息维护 -->
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="企业名称" prop="enterpriseName">
        <el-input
          v-model="queryParams.enterpriseName"
          placeholder="请输入企业名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车牌号" prop="plate">
        <el-input
          v-model="queryParams.plate"
          placeholder="请输入车牌号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table
      border
      fit
      highlight-current-row
      empty-text="暂无数据"
      v-loading="loading"
      :data="vehicleinfoList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="企业名称" align="center" prop="transportationCompanyName" />

      <el-table-column label="车牌号" align="center" prop="plate" />
      <el-table-column label="车辆名称" align="center" prop="name" />
      <el-table-column label="车主姓名" align="center" prop="ownName" />
      <el-table-column label="车主电话" align="center" prop="ownerPhone" />
      <el-table-column label="车辆颜色" align="center" prop="plateColor" />
      <el-table-column label="车辆承载吨数" align="center" prop="carLoadBearing" />

      <!-- <el-table-column label="车辆类型" align="center" prop="vehicleType" />
      <el-table-column label="货厢体积m³" align="center" prop="cargoVolume" />
      <el-table-column label="车辆品牌" align="center" prop="vehicleBrand" />-->
      <el-table-column
        fixed="right"
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-info"
            @click="handleDesc(scope.row)"
            v-hasPermi="['modules:info:query']"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改车辆信息对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      @beforeClose="beforeCloseDesx"
      width="80%"
      style=" min-width: 800px;"
      append-to-body
    >
      <dialogCLXX ref="aa" :form="form" />
    </el-dialog>
  </div>
</template>

<script>
import {
  listVehicleinfo,
  getVehicleinfo,
  delVehicleinfo,
  addVehicleinfo,
  updateVehicleinfo
} from "@/api/manger/vehicleinfo";

import dialogCLXX from "./components/index";

export default {
  name: "Vehicleinfo",
  components: { dialogCLXX },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 车辆信息表格数据
      vehicleinfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        oldCarId: null,
        vehicleType: null,
        vehicleColor: null,
        cargoVolume: null,
        specialLicensePlate: null,
        vehicleStar: null,
        vehicleBrand: null,
        vehicleModel: null,
        vehicleAge: null,
        dealer: null,
        productionDate: null,
        annualInspectionDate: null,
        validUntil: null,
        registrationDate: null,
        eliminationDate: null,
        licenseAttachment: null,
        otherAttachment: null,
        vehiclePhotoAttachment: null,
        vehicleRegistrationAttachment: null,
        cargoBoxPhotoAttachment: null,
        vehicleDrivingLicenseAttachment: null,
        exts: null,
        driverId: null,
        ownName: null,
        contact: null,
        vin: null,
        teamId: null,
        plate: null,
        plateColor: null,
        simCard: null,
        tmnNo: null,
        tmnKey: null,
        keyType: null,
        enterpriseId: null,
        enterpriseName: null,
        type: null,
        channelCount: null,
        audioCode: null,
        cloudChannel: null,
        commChannel: null,
        broadcastChannel: null,
        customizedChannels: null,
        customizedNames: null,
        oldTmnId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        oldCarId: [
          { required: true, message: "车辆id不能为空", trigger: "blur" }
        ],
        vehicleType: [
          {
            required: true,
            message: "车辆类型-必填不能为空",
            trigger: "change"
          }
        ],
        vehicleColor: [
          { required: true, message: "车身颜色-必填不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询车辆信息列表 */
    getList() {
      this.loading = true;
      listVehicleinfo(this.queryParams).then(response => {
        this.vehicleinfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        oldCarId: null,
        vehicleType: null,
        vehicleColor: null,
        cargoVolume: null,
        specialLicensePlate: null,
        vehicleStar: null,
        vehicleBrand: null,
        vehicleModel: null,
        vehicleAge: null,
        dealer: null,
        productionDate: null,
        annualInspectionDate: null,
        validUntil: null,
        registrationDate: null,
        eliminationDate: null,
        licenseAttachment: null,
        otherAttachment: null,
        vehiclePhotoAttachment: null,
        vehicleRegistrationAttachment: null,
        cargoBoxPhotoAttachment: null,
        vehicleDrivingLicenseAttachment: null,
        exts: null,
        driverId: null,
        ownName: null,
        contact: null,
        vin: null,
        teamId: null,
        plate: null,
        plateColor: null,
        simCard: null,
        tmnNo: null,
        tmnKey: null,
        keyType: null,
        enterpriseId: null,
        enterpriseName: null,
        type: null,
        channelCount: null,
        audioCode: null,
        cloudChannel: null,
        commChannel: null,
        broadcastChannel: null,
        customizedChannels: null,
        customizedNames: null,
        oldTmnId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加车辆信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getVehicleinfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改车辆信息";
      });
    },
    /** 详情按钮操作 */
    handleDesc(row) {
      this.reset();
      const id = row.id || this.ids;
      getVehicleinfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "车辆信息详情";
      });
    },
    beforeCloseDesx(action, instance, done) {
      done();
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateVehicleinfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addVehicleinfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除车辆信息编号为"' + ids + '"的数据项？')
        .then(function() {
          return delVehicleinfo(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "manger/vehicleinfo/export",
        {
          ...this.queryParams
        },
        `vehicleinfo_${new Date().getTime()}.xlsx`
      );
    }
  }
};
</script>
